var amqp = require('amqplib/callback_api');
amqp.connect('amqp://localhost', function(err, conn) {
	conn.createChannel(function(err, ch) {
		var ex = 'direct_logs'; // exchange
		var msg = 'hello world ';
		ch.assertExchange(ex, 'direct', {
			durable: false
		});

		// send to exchange
		var levels = ['debug', 'info', 'error'];
		var level;
		setInterval(function() {
			level = Math.floor(Math.random() * 3);
			ch.publish(ex, levels[level], new Buffer(msg + levels[level]));
			console.log(" [x] %s, %s", levels[level], msg);
		}, 2000);
	});
});

// node p.js